import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.Arrays;
import static org.junit.jupiter.api.Assertions.*;

class NGuessNumberTest {
    NGuessNumber ngn;

    @BeforeEach
    void setUp() {
        ngn = new NGuessNumber();
    }

    @Test
    void generateAnswer() {
        ArrayList<Integer> answers = ngn.generateAnswer();
        // 断言答案长度是否为4
        assertEquals(4, answers.size());
        // 断言数字是否在0-9且不重复
        for (int num : answers) {
            assertTrue(num >= 0 && num <= 9);
        }
        for (int i = 0; i < answers.size(); i++) {
            for (int j = i + 1; j < answers.size(); j++) {
                assertNotEquals(answers.get(i), answers.get(j));
            }
        }
    }

    @Test
    void getA() {
        // 设置答案 [1,2,3,4]
        ngn.answers = new ArrayList<>(Arrays.asList(1, 2, 3, 4));
        // 测试完全匹配
        ngn.guesses = new ArrayList<>(Arrays.asList(1, 2, 3, 4));
        assertEquals(4, ngn.getA());
        // 测试部分匹配
        ngn.guesses = new ArrayList<>(Arrays.asList(1, 5, 6, 7));
        assertEquals(1, ngn.getA());
    }

    @Test
    void getB() {
        // 设置答案 [1,2,3,4]
        ngn.answers = new ArrayList<>(Arrays.asList(1, 2, 3, 4));
        // 测试完全错位
        ngn.guesses = new ArrayList<>(Arrays.asList(4, 3, 2, 1));
        assertEquals(4, ngn.getB());
        // 测试部分错位
        ngn.guesses = new ArrayList<>(Arrays.asList(2, 1, 5, 6));
        assertEquals(2, ngn.getB());
    }
}